home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / editor.js < prev    next >
Encoding:
JavaScript  |  2007-07-24  |  69.9 KB  |  1,711 lines

  1. /* 
  2. --------------------------------
  3. Editor UI and Overlay javascript
  4. --------------------------------
  5. */
  6.  
  7. /*
  8. Todo: remove global variables and place equivalents in a performancing object
  9. */
  10. var gPerformancingVersion = "1.4.2";
  11. var gPerformancingVersionUA = "1.4.2";
  12. var gSelectedBlog = null;
  13. var gLastXMLBlogObject = null;
  14. var gPerformanceDidGetRSS = false;
  15. var gPerformanceLastURL = null;
  16. var gPffDeliciosTagArray = [];
  17. var gPffDeliciousTimeOut = null;
  18. var gPffTechnoratiTimeOut = null;
  19. var gPffOnPublishTimeOut = null;
  20. var gPffTrackBackTemp = null;
  21. var gPFFLastTags = null;
  22. var gPFFLastTrackbacks = "";
  23. var gPFFFirstWindow = null;
  24.  
  25. var gPerFormancingColorPick = false; //Keep color picker from triggering twice (bad hack)
  26.  
  27. var performancingUI = new Object();
  28.  
  29. performancingUI.init = function() {
  30.     performancingMidas.setUpMidas();
  31.     gSelectedBlog = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  32.     performancingUI.uiINIT();
  33.     performancingUI.onTextBoxLoad2();
  34.     
  35.     gPFFFirstWindow = performancingUI.getLastWindow();
  36.     if(gSelectedBlog != null && gSelectedBlog != 'null'){
  37.         window.setTimeout('performancingUI.getAboutRSS()', 3500, true);
  38.     }
  39.     var richTextBox = document.getElementById("performancing-message");
  40.     richTextBox.contentWindow.focus();
  41.     //performancingUI.init();
  42.     //performancingMidas.placeCaretLite(richTextBox);
  43.     
  44.     performancingUI.setCSS();
  45.     performancingUI.initTechnorati();
  46.     performancingUI.doUpgrade();
  47.     this.sourceSpellCheck = new pffSpellCheck();
  48.     this.richSpellCheck = new pffSpellCheck();
  49.     
  50.     this.sourceSpellCheck.setupTextBoxSpellCheck();
  51.     this.richSpellCheck.setupEditorSpellCheck();
  52.     
  53.     this.theSpellcheck = this.richSpellCheck;
  54.     gPerformancingUtil.loadXMLFIle();
  55.     //Open Last viewed window
  56.     var lastOpenedEditTab = null;
  57.     try{
  58.         lastOpenedEditTab = gPerformancingUtil.prefs.getCharPref('display.state.lastviewopened');
  59.     }catch(e){
  60.         lastOpenedEditTab = "tab-normal-edit";
  61.     }
  62.     var lastOpenedEditTabObj = document.getElementById(lastOpenedEditTab);
  63.     performancingMidas.viewTab(lastOpenedEditTabObj);
  64.     //window.setTimeout('performancingUI.setUpSpellCheck();', 1500, true);
  65. }
  66.  
  67. performancingUI.setUpSpellCheck = function() {
  68.     
  69. }
  70.  
  71. performancingUI.doUpgrade = function() {
  72.     var isFirstRun = gPerformancingUtil.prefs.getBoolPref("onfirstrun");
  73.     if(isFirstRun){
  74.         //Start All Upgrades
  75.         //For all upgrades
  76.         var fromPFFVersion = null;
  77.         try{
  78.             fromPFFVersion = gPerformancingUtil.prefs.getCharPref('extra.version.lastinstalled');
  79.         }catch(e){}
  80.         if(fromPFFVersion != null){
  81.             gPerformancingUtil.prefs.setCharPref('extra.version.lastinstalled', gPerformancingVersion);
  82.             gPerformancingUtil.prefs.setCharPref('extra.version.previous', fromPFFVersion);
  83.         }else{
  84.             gPerformancingUtil.prefs.setCharPref('extra.version.lastinstalled', gPerformancingVersion);
  85.             gPerformancingUtil.prefs.setCharPref('extra.version.previous', "");
  86.         }
  87.         // End for All
  88.         
  89.         //Start 1.2 -> 1.3 upgrade 
  90.         // Let's set insert pff by default respecting 1.2 upgraders
  91.         var hasBlog = gPerformancingUtil.prefs.prefHasUserValue("settings.lastselected.blog");
  92.         var insertPFFValue = true;
  93.         try{
  94.             insertPFFValue = gPerformancingUtil.prefs.getBoolPref('extra.insertpfftext');
  95.         }catch(e){}
  96.         //Insert Powered by Performancing
  97.         if( hasBlog ){
  98.             gPerformancingUtil.prefs.setBoolPref('extra.insertpfftext2', insertPFFValue);
  99.         }//else default is already true
  100.         // End from 1.2 upgrade
  101.         
  102.         
  103.         // END first run
  104.         gPerformancingUtil.prefs.setBoolPref("onfirstrun", false);
  105.     }
  106. }
  107. performancingUI.setCSS = function() {
  108.     //performancingUI.setCSS
  109.     var winPreview = document.getElementById("performancing-preview-display");
  110.     var previewCSS = winPreview.contentDocument.getElementById("performancing-preview-css");
  111.     previewCSS.href = gPerformancingUtil.prefs.getCharPref("content.preview.cssurl");
  112. }
  113.  
  114. performancingUI.initTechnorati = function() {
  115.     var isAuto = gPerformancingUtil.prefs.getBoolPref("extra.inserttechnorati");
  116.     document.getElementById("performancing-technorati-tags-button").hidden = isAuto;
  117.     document.getElementById("performancing-technorati-extrainfo").hidden = !isAuto;
  118. }
  119.  
  120. performancingUI.launchWindow = function(xulDoc) {
  121.     window.open(xulDoc, '_blank', 'chrome,centerscreen,resizable=yes,titlebar=yes,dependent=yes')
  122. }
  123.  
  124. performancingUI.reLoadBlogs = function() {
  125.     gPerformancingUtil.loadXMLFIle();
  126.     //alert('Refreshed xml');
  127. }
  128.  
  129. performancingUI.onBlogSelect = function(theListElement) {
  130.     var theSelectedBlogUID = theListElement.getAttribute('blogGUID');
  131.     var theSelectedBlogURL = theListElement.getAttribute('tooltiptext');
  132.     
  133.     performancingUI.setBlogAsSelected(theSelectedBlogUID, theSelectedBlogURL);
  134. }
  135.  
  136. performancingUI.setBlogAsSelected = function(theSelectedBlogUID, theSelectedBlogURL) {
  137.     gSelectedBlog = theSelectedBlogUID;
  138.     gPerformancingUtil.prefs.setCharPref("settings.lastselected.blog", gSelectedBlog);
  139.     
  140.     performancingUI.showCurrentBlog(theSelectedBlogUID, theSelectedBlogURL);
  141. }
  142.  
  143. performancingUI.toggleNavbar = function() {
  144.     var theNavBar = document.getElementById('performancing-navbar');
  145.     var toggltBtn = document.getElementById('performancing-navbar-toggle');
  146.     var isCollapsed = theNavBar.collapsed;
  147.     theNavBar.collapsed = !isCollapsed;
  148.     if(isCollapsed){
  149.         toggltBtn.setAttribute("state", "open");
  150.         var localeString = performancingUI.getLocaleString('closesidebar', []);
  151.         toggltBtn.setAttribute('tooltiptext', localeString);
  152.     }else{
  153.         toggltBtn.setAttribute("state", "closed");
  154.         var localeString = performancingUI.getLocaleString('opensidebar', []);
  155.         toggltBtn.setAttribute('tooltiptext', localeString);
  156.     }
  157. }
  158.  
  159. performancingUI.onSidebarTabSelect = function(theSBTabElement, hideEditButtons) {
  160.     var theDeckIndex = theSBTabElement.getAttribute('deck');
  161.     var theNavBoxInfo = document.getElementById('performancing-sidebar-vbox');
  162.     theNavBoxInfo.setAttribute('selectedIndex', theDeckIndex);
  163.     
  164.     var numberOfNavs = document.getElementById('performancing-sidebarnav-hbox-0').getElementsByTagName("label").length;
  165.     var theGoodOne = 0;
  166.     
  167.     // Close all the other boxes
  168.     for (var i = 0; i < numberOfNavs; i++){
  169.         if (i == theDeckIndex){
  170.             theGoodOne = i;
  171.         } else {
  172.             document.getElementById('blog-sidebar-listing-'+i).setAttribute('collapsed', true);
  173.         }
  174.         document.getElementById('performancing-sb-tab'+i).setAttribute('selected', false); //currentlySelectedTab
  175.     }
  176.     
  177.     document.getElementById('blog-sidebar-listing-'+theGoodOne).setAttribute('collapsed', false);
  178.     theSBTabElement.setAttribute('selected', true);
  179.     
  180.     if (hideEditButtons) {
  181.         document.getElementById("post-edit-buttons").hidden = true;
  182.     }
  183. }
  184.  
  185. performancingUI.onLeftSidebarTabSelect = function(theTab) {
  186.     var theNavBox = document.getElementById('performancing-navbar-tabs');
  187.     var theAddonNavBox = document.getElementById('performancing-navbar-tabs-addons');
  188.     var numberOfTabs = theNavBox.childNodes.length;
  189.     var doCollapse = true;
  190.     //Close all the other boxes
  191.     for(var i=0; i < numberOfTabs; i++){
  192.         theNavBox.childNodes[i].setAttribute('selected', false);
  193.     }
  194.     
  195.     numberOfTabs = theAddonNavBox.childNodes.length;
  196.     for(var i=0; i < numberOfTabs; i++){
  197.         theAddonNavBox.childNodes[i].setAttribute('selected', false);
  198.     }
  199.     
  200.     var theName = "";
  201.     try{
  202.         theName = theTab.getAttribute("name");
  203.     }catch(e){
  204.         theName = theTab.toString();
  205.     }
  206.     //Set the selected tab
  207.     document.getElementById('performancing-' + theName + '-tab').setAttribute('selected', true);
  208.     
  209.     var theMainDeck = document.getElementById('performancing-main-content-deck');
  210.     
  211.     var theSwitchVar = theName;
  212.     var theAddon = "";
  213.     
  214.     try{
  215.         theAddon = theTab.getAttribute("addon");
  216.     }catch(e){}
  217.     
  218.     if(theAddon == "custom"){
  219.         theSwitchVar = theAddon;
  220.     }
  221.     //First uncollapse the one we selected collapsed="true"
  222.     if(theName != 'notes' && theName != 'addons'){
  223.         document.getElementById('performancing-'+ theName +'-content').setAttribute('collapsed', false);
  224.     }
  225.     
  226.     switch(theSwitchVar){                                                                  
  227.         case 'editor':
  228.             theMainDeck.setAttribute('selectedIndex','0');
  229.             var theEditorEl = document.getElementById('performancing-sb-tab0');
  230.             performancingUI.onSidebarTabSelect(theEditorEl);
  231.             performancingMidas.toggleSidebar(true);
  232.             //performancingMidas.makeBlank();
  233.             break;
  234.             
  235.         case 'notes':
  236.             theMainDeck.setAttribute('selectedIndex','0');
  237.             var theEditorEl = document.getElementById('performancing-sb-tab3');
  238.             performancingUI.onSidebarTabSelect(theEditorEl);
  239.             performancingMidas.toggleSidebar(true);
  240.             //performancingMidas.makeBlank();
  241.             break;
  242.             
  243.         case 'settings':
  244.             theMainDeck.setAttribute('selectedIndex','1');
  245.             this.loadSettings();//performancingUI.loadSettings
  246.             break;
  247.             
  248.         case 'technorati':
  249.             theMainDeck.setAttribute('selectedIndex','2');
  250.             performancingUI.getPageInfo('technorati');
  251.             break;
  252.             
  253.         case 'delicious':
  254.             theMainDeck.setAttribute('selectedIndex','3');
  255.             performancingUI.deliciousOnLoad();
  256.             performancingUI.getPageInfo('delicious');
  257.             break;
  258.             
  259.         case 'about':
  260.             theMainDeck.setAttribute('selectedIndex','4');
  261.             if(!gPerformanceDidGetRSS){
  262.                 performancingUI.getAboutRSS();
  263.             }
  264.             break;
  265.             
  266.         case 'addons':
  267.             pffAddonSkin.loadAddonTabs(theTab);
  268.             doCollapse = false;
  269.             break;
  270.             
  271.         case 'custom':
  272.             pffAddonSkin.onAddonTabClick(theTab);
  273.             break;
  274.             
  275.     }
  276.     //Collapse all other
  277.     if(doCollapse){
  278.         this.collapseContent(theName);
  279.     }
  280. }
  281.  
  282. //We collapse the elements to keep resizing space
  283. performancingUI.collapseContent = function(notThisOne) {
  284.     //var theEditorEl = document.getElementById('performancing-settings-content');
  285.     
  286.     //Now collapse all the others
  287.     //var contentArray = ['delicious', 'editor', 'settings', 'about', 'technorati'];
  288.     //Only collapse elements that need to be (those that don't overdlow)
  289.     var contentArray = ['editor', 'settings', 'about'];
  290.     for(var i = 0; i < contentArray.length ; i++){
  291.         var theContent = document.getElementById('performancing-'+ contentArray[i] +'-content');
  292.         if(notThisOne == contentArray[i]){
  293.             //theContent.setAttribute('collapsed', false);
  294.         }else{
  295.             theContent.setAttribute('collapsed', true);
  296.         }
  297.     }
  298. }
  299.  
  300. performancingUI.checkSubjectEmpty = function() {
  301.     var theSubjectEntry = document.getElementById("performancing-editor-subject").value;
  302.     if(theSubjectEntry.length < 2 ){
  303.         var localeString = performancingUI.getLocaleString('subjectisblank', []);
  304.         return confirm(localeString);
  305.     }else{
  306.         return true;
  307.     }
  308. }
  309.  
  310. performancingUI.postSuccessful = function() {
  311.     var thePublishDeck = document.getElementById('performancing-feedback-deck');;
  312.     thePublishDeck.setAttribute('selectedIndex','0');
  313.     window.clearTimeout(gPffOnPublishTimeOut);
  314. }
  315.  
  316. performancingUI.okClearPost = function(isClear) {
  317.     gPFFLastTags = document.getElementById("performancing-technorati-tags").value;
  318.     gPFFLastTrackbacks = document.getElementById("performancing-trackback-textbox").value;
  319.     if(isClear){
  320.         performancingUI.clearTechnoratiTags();
  321.         gPerformancingUtil.checkCategories(false);
  322.         performancingUI.clearTrackbacks();
  323.         performancingMidas.makeBlank();
  324.         performancingUI.toggleExtraOptDeck(true);
  325.     }
  326.     var thePublishDeck = document.getElementById('performancing-feedback-deck');;
  327.     thePublishDeck.setAttribute('selectedIndex','1');
  328.     performancingUI.onProgressOff();
  329. }
  330.  
  331. performancingUI.onServerSend = function() {
  332.     var thePublishDeck = document.getElementById('performancing-publish-deck');;
  333.     thePublishDeck.setAttribute('selectedIndex','1');
  334.     gPffOnPublishTimeOut = window.setTimeout('performancingUI.onProgressOff()', 20000, true);
  335. }
  336.  
  337. performancingUI.onProgressOff = function() {
  338.     var thePublishDeck = document.getElementById('performancing-publish-deck');
  339.     thePublishDeck.setAttribute('selectedIndex','0');
  340. }
  341.  
  342. performancingUI.showCurrentBlog = function(aUID, aURL) {
  343.     var theBlogXML = gLastXMLBlogObject.blogs.blog.(GUID == aUID );
  344.     
  345.     var theBlogStatus = document.getElementById("performancing-blogstatus");
  346.    
  347.     if( theBlogXML.blogname.toString() == "" ){
  348.         var localeString = performancingUI.getLocaleString('noblogselected', []);
  349.         theBlogStatus.value = localeString;
  350.     }else{
  351.         theBlogStatus.value = theBlogXML.blogname.toString();
  352.         
  353.         gPerformancingUtil.serviceObjectXML = theBlogXML;
  354.         gPerformancingUtil.serviceObject = bfXMLRPC.setUpBlogObject(theBlogXML);
  355.         
  356.         window.setTimeout('gPerformancingUtil.getBlogHistory("'+aUID+'")', 1000, true);
  357.         window.setTimeout('gPerformancingUtil.getCategoryList("'+aUID+'")', 2000, true);
  358.                 
  359.         gPerformancingUtil.setUpAPISpecificFunctions(aUID);
  360.     }
  361.     
  362.     //Now show it selected
  363.     var blogGroup = document.getElementById("blog-group");
  364.     var blogItems = blogGroup.getElementsByTagName("radio");
  365.     var numberOfBlogs = blogItems.length;
  366.  
  367.     for (var i = 0; i < numberOfBlogs; i++){
  368.         var theGUID = blogItems[i].getAttribute("blogGUID");
  369.         if(theGUID == gSelectedBlog ){
  370.             blogGroup.selectedItem = blogItems[i];
  371.             break;
  372.         }
  373.     }
  374.     
  375.     var publishButtonLabel = performancingUI.getLocaleString("publishToBlog", [  theBlogXML.blogname.toString() ]);
  376.     document.getElementById("performancing-publish-button").setAttribute("label", publishButtonLabel);
  377.     
  378.     var editButtons = document.getElementById("post-edit-buttons");
  379.     editButtons.hidden = true;
  380. }
  381.  
  382. performancingUI.toggleEnableOnPost = function() {
  383.     /* var richTextBox = document.getElementById("performancing-message");
  384.     var SourceTextBox = document.getElementById("performancing-message-source");
  385.     richTextBox.disabled = !richTextBox.disabled;
  386.     SourceTextBox.disabled = !SourceTextBox.disabled; */
  387.     
  388.     var editButtons = document.getElementById("post-edit-buttons");
  389.     editButtons.hidden = true;
  390.     
  391.     var noteButton = document.getElementById("performancing-resavenote-button");
  392.     noteButton.hidden = true;
  393.     
  394. }
  395.  
  396. performancingUI.clearAll = function() {
  397.     performancingMidas.makeBlank();
  398.     performancingUI.toggleExtraOptDeck(true);
  399.     this.toggleEnableOnPost();
  400.     performancingUI.clearTechnoratiTags();
  401. }
  402.  
  403. performancingUI.openInTab = function(aURL) {
  404.     var myLastWin = performancingUI.getLastWindow();
  405.     var editorInTab = myLastWin.gBrowser.addTab(aURL);
  406.     myLastWin.getBrowser().selectedTab = editorInTab;
  407. }
  408.  
  409. performancingUI.getLastWindow = function() {
  410.     var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
  411.     var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  412.     var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" );
  413.     
  414.     if (topWindowOfType) {
  415.         return topWindowOfType;
  416.     }else{
  417.         return null;
  418.     }
  419. }
  420.  
  421. performancingUI.blogThis = function() {
  422.     var thePageProps = this.getLastPageURInTitle();
  423.     var theURL = thePageProps[0];
  424.     var theTitle = thePageProps[1];
  425.     
  426.     var selectedContent = null;
  427.     try{
  428.         var focusedWindow = document.commandDispatcher.focusedWindow;  
  429.         if (focusedWindow == window){
  430.               focusedWindow = _content;
  431.               }
  432.             var docCharset = null;
  433.             if (focusedWindow){
  434.               docCharset = "charset=" + focusedWindow.document.characterSet;
  435.         }
  436.         //selectedContent = focusedWindow.__proto__.getSelection.call(focusedWindow).toString();
  437.         selectedContent = focusedWindow.getSelection().toString();
  438.     }catch(e){
  439.         //foo
  440.     }
  441.     //alert("Title: "+theTitle+ " URL: " + theURL);
  442.     performancingUI.doBlogThisInsert(theTitle, theURL, selectedContent);
  443. }
  444.  
  445. performancingUI.openAboutFromEM = function() {
  446.     gperformancing.openBottomBar(true, true);
  447.     var myIframeWindow = document.getElementById('perFormancingMidasFrame').contentWindow;
  448.     myIframeWindow.setTimeout("performancingUI.onLeftSidebarTabSelect('about')", 1000, true);
  449. }
  450.  
  451. performancingUI.openTechnorati = function() {
  452.     gperformancing.openBottomBar(true, true);
  453.     var myIframeWindow = document.getElementById('perFormancingMidasFrame').contentWindow;
  454.     myIframeWindow.setTimeout("performancingUI.onLeftSidebarTabSelect('technorati')", 1000, true);
  455. }
  456.  
  457. performancingUI.openDelicious = function() {
  458.     gperformancing.openBottomBar(true, true);
  459.     var myIframeWindow = document.getElementById('perFormancingMidasFrame').contentWindow;
  460.     myIframeWindow.setTimeout("performancingUI.onLeftSidebarTabSelect('delicious')", 1000, true);
  461. }
  462.  
  463. performancingUI.doBlogThisInsert = function(theTitle, theURL, selectedContent) {
  464.     var textToAppend = null;
  465.     selectedContent = selectedContent.toString();
  466.     if(selectedContent != null && selectedContent != "" ){
  467.         textToAppend = "<a href=\"" +theURL+ "\" >" + theTitle + "</a> <br/> <blockquote>" + selectedContent + "</blockquote";
  468.     }else{
  469.         textToAppend = "<a href=\"" +theURL+ "\" >" + theTitle + "</a>";
  470.     }
  471.     //gPFFBlogThisText
  472.     //Open up the inline bar if it's not open
  473.     if(!gperformancing.isOpen()){
  474.         gPFFBlogThisText = [];
  475.         gPFFBlogThisText.push(true);
  476.         gPFFBlogThisText.push(textToAppend);
  477.         gperformancing.openBottomBar(true);
  478.     }else{
  479.         this.doInsert(textToAppend);
  480.         gperformancing.openBottomBar(true);
  481.     }
  482. }
  483. performancingUI.onLoadInsert = function() {
  484.     var theWindow = performancingUI.getLastWindow();
  485.     if(theWindow.gPFFBlogThisText[0] == true){
  486.         this.doInsert(theWindow.gPFFBlogThisText[1]);
  487.         //alert("It's true");
  488.         theWindow.gPFFBlogThisText = [];//No clear the memory
  489.     }
  490.     //alert("It's FALSE");
  491. }
  492.  
  493. performancingUI.doInsert = function(textToAppend) {
  494.     var myDoc = performancingUI.getPffDoc();
  495.     var tabbox = myDoc.getElementById("performancing-editor-tabbox");
  496.     //var theTitle = myDoc.getElementById("performancing-editor-subject").value;
  497.     if(tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){//Rich or preview
  498.             var winNormal = myDoc.getElementById("performancing-message");
  499.             winNormal.contentWindow.document.body.innerHTML = winNormal.contentWindow.document.body.innerHTML + "<br/>" + textToAppend;
  500.         }else if(tabbox.selectedIndex == 1){ //Source
  501.             var theSourceBox = myDoc.getElementById("performancing-message-source");
  502.             theSourceBox.value = theSourceBox.value + "<br/>" + textToAppend;
  503.         }else{
  504.         //alert('PerFormancing Error: Could not find Note content, please contact the author');
  505.     }
  506. }
  507.  
  508. performancingUI.getPffDoc = function() {
  509.     var myIframeDocument = null;
  510.     try{
  511.         myIframeDocument = document.getElementById('perFormancingMidasFrame').contentDocument;
  512.     }catch(e){
  513.         myIframeDocument = document;
  514.     }
  515.     return myIframeDocument;
  516. }
  517.  
  518. performancingUI.getRichEditor = function() {
  519.     var myDoc = performancingUI.getPffDoc();
  520.     var theEditor = myDoc.getElementById("performancing-message");
  521.     return theEditor;
  522. }
  523.  
  524. performancingUI.getRichEditorWindow = function() {
  525.     var theEditor = performancingUI.getRichEditor();
  526.     return theEditor.contentWindow;//.document.body.innerHTML
  527. }
  528.  
  529. performancingUI.getPreviewWindow = function() {
  530.     var myDoc = performancingUI.getPffDoc();
  531.     var thePreview = myDoc.getElementById("performancing-preview-display");
  532.     
  533.     return thePreview.contentWindow;
  534. }
  535.  
  536. performancingUI.onEditFocus = function() {
  537. }
  538. performancingUI.onSubjectKeyPress = function(theInput, event) {
  539.     //dump("\n\n SUBJECT KEYPRESS: " + event.keyCode + "\n\n");
  540.     if (theInput.value == "") return 0;
  541.     
  542.     if (event.keyCode == 8){
  543.         //dontGetArray = "0";
  544.         return 0;
  545.     }else if(event.keyCode == 13){
  546.         theInput.selectionStart = theInput.selectionEnd;
  547.     }
  548.     this.populateArray(theInput,event);
  549.     return 1;
  550. }
  551.  
  552. performancingUI.onBoolSettingsSet = function(theInput) {
  553.     var theWindow = performancingUI.getLastWindow();
  554.     var theCheckBoxPref = theInput.getAttribute('pref');
  555.     var theCheckBoxChecked = theInput.checked;
  556.     gPerformancingUtil.prefs.setBoolPref(theCheckBoxPref, theCheckBoxChecked);
  557.     
  558.     switch(theCheckBoxPref){
  559.         case 'display.onbottom':
  560.             alert("This settings requires a browser restart.");
  561.             break;
  562.             
  563.         case 'settings.usecss':
  564.             var midas = document.getElementById("performancing-message");
  565.             midas.contentDocument.execCommand("styleWithCSS", false, theCheckBoxChecked);
  566.             break;
  567.             
  568.         case 'settings.saveonexit':
  569.             //foo
  570.             break;
  571.             
  572.         case 'display.hideContextMenu':
  573.             theWindow.gperformancing.showHideCM();
  574.             break;
  575.             
  576.         case 'settings.showextrapuboptions':
  577.             performancingUI.uiINIT();
  578.             break;
  579.             
  580.         case 'extra.inserttechnorati':
  581.             performancingUI.initTechnorati();
  582.             break;
  583.             
  584.         case 'extra.insertpfftext2':
  585.             //nothing
  586.             break;
  587.             
  588.         case 'display.hidetechnorati':
  589.             performancingUI.uiINIT();
  590.             break;
  591.             
  592.         case 'display.hidedelicious':
  593.             performancingUI.uiINIT();
  594.             break;
  595.             
  596.         case 'publish.checkdraft':
  597.             performancingUI.uiINIT();
  598.             break;
  599.             
  600.         case 'display.enablertl':
  601.             performancingUI.onTextBoxLoad2();
  602.             break;
  603.             
  604.         case 'display.sortcats':
  605.             //nothing
  606.             break;
  607.     }
  608. }
  609.  
  610. performancingUI.loadSettings = function() {
  611.   //var boolSettingsArray = [,,];
  612.   try{
  613.       document.getElementById("performancing-settings-remember-editor").checked = gPerformancingUtil.prefs.getBoolPref('settings.saveonexit');
  614.   }catch (e){
  615.       document.getElementById("performancing-settings-remember-editor").checked = false;
  616.   }
  617.   
  618.   try{
  619.       document.getElementById("performancing-settings-display-usecss").checked = gPerformancingUtil.prefs.getBoolPref('settings.usecss');
  620.   }catch (e){
  621.       document.getElementById("performancing-settings-display-usecss").checked = false;
  622.   }
  623.   
  624.   try{
  625.       document.getElementById("performancing-settings-display-onbottom-check").checked = gPerformancingUtil.prefs.getBoolPref('display.onbottom');
  626.   }catch (e){
  627.       document.getElementById("performancing-settings-display-onbottom-check").checked = false;
  628.   }
  629.   
  630.   try{
  631.       document.getElementById("performancing-settings-display-cm-check").checked = gPerformancingUtil.prefs.getBoolPref('display.hideContextMenu');
  632.   }catch (e){
  633.       document.getElementById("performancing-settings-display-cm-check").checked = false;
  634.   }
  635.   try{
  636.       document.getElementById("performancing-settings-show-extra-pub").checked = gPerformancingUtil.prefs.getBoolPref('settings.showextrapuboptions');
  637.   }catch (e){
  638.       document.getElementById("performancing-settings-show-extra-pub").checked = false;
  639.   }
  640.   try{
  641.       document.getElementById("performancing-settings-auto-technorati").checked = gPerformancingUtil.prefs.getBoolPref('extra.inserttechnorati');
  642.   }catch (e){
  643.       document.getElementById("performancing-settings-auto-technorati").checked = false;
  644.   }
  645.   
  646.   try{
  647.       document.getElementById("performancing-settings-cssurl").value = gPerformancingUtil.prefs.getCharPref('content.preview.cssurl');
  648.   }catch (e){
  649.   }
  650.   
  651.   try{
  652.       document.getElementById("performancing-settings-display-technorati").checked = gPerformancingUtil.prefs.getBoolPref('display.hidetechnorati');
  653.   }catch (e){
  654.       document.getElementById("performancing-settings-display-technorati").checked = false;
  655.   }
  656.   try{
  657.       document.getElementById("performancing-settings-display-delicious").checked = gPerformancingUtil.prefs.getBoolPref('display.hidedelicious');
  658.   }catch (e){
  659.       document.getElementById("performancing-settings-display-delicious").checked = false;
  660.   }
  661.   try{
  662.       document.getElementById("performancing-settings-auto-draft").checked =  gPerformancingUtil.prefs.getBoolPref('publish.checkdraft');
  663.   }catch (e){
  664.       document.getElementById("performancing-settings-auto-draft").checked = false;
  665.   }
  666.   try{
  667.       document.getElementById("performancing-settings-display-sortcats").checked =    gPerformancingUtil.prefs.getBoolPref('display.sortcats');
  668.   }catch (e){
  669.       document.getElementById("performancing-settings-display-sortcats").checked = false;
  670.   }     
  671.   try{
  672.       document.getElementById("performancing-settings-auto-pffpowered").checked = gPerformancingUtil.prefs.getBoolPref('extra.insertpfftext2');
  673.   }catch (e){
  674.       document.getElementById("performancing-settings-auto-pffpowered").checked = false;
  675.   }
  676.   
  677.   try{
  678.       document.getElementById("performancing-settings-display-rtl").checked = gPerformancingUtil.prefs.getBoolPref('display.enablertl');
  679.   }catch (e){
  680.       document.getElementById("performancing-settings-display-rtl").checked = false;
  681.   }
  682.   
  683. }
  684.  
  685. performancingUI.getAboutRSS = function() {
  686.     var RSSurl = 'http://www.scribefire.com/feed/';
  687.     //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass)
  688.     var theCall = new PffXmlHttpReq(RSSurl, "POST", '', false, null, null);
  689.     
  690.     theCall.onResult = function( aText, aXML ){
  691.         performancingUI.setAboutRSS( aText );
  692.     }
  693.     theCall.onError = function (aStatusMsg, Msg) {
  694.         //foo
  695.     }
  696.     theCall.prepCall(); //Set up The call (open connection, etc.)
  697.     theCall.request.setRequestHeader("Content-Type", "text/xml");
  698.     theCall.request.setRequestHeader("User-Agent", "ScribeFire " + gPerformancingVersionUA);
  699.     theCall.makeCall(); //Make the call
  700.     theCall.request.overrideMimeType ('text/xml');
  701. }
  702.  
  703. performancingUI.setAboutRSS = function(theData) {
  704.     try{
  705.         gPerformanceDidGetRSS = true;
  706.         var titlesArray = theData.match(/(?:\<title\>)(.*\w*)(?=<\/title>)/mgi)
  707.         var linksArray = theData.match(/(?:\<link\>)(.*\w*)(?=<\/link>)/mgi)
  708.         var rssLength = titlesArray.length;
  709.         gPerformancingUtil.clearCheckListOut("performancing-about-rss");
  710.         //performancingUI.addItemToRSSList("Loading feeds...", "");
  711.         
  712.         for(i=1; i< rssLength && i < 6; i++){
  713.             var aTitle = titlesArray[i].replace("<title>", "");
  714.             var aLink  = linksArray[i].replace("<link>", "");
  715.             performancingUI.addItemToRSSList(aTitle, aLink);
  716.         }
  717.     }catch(e){
  718.         gPerformancingUtil.clearCheckListOut("performancing-about-rss");
  719.         var localeString = performancingUI.getLocaleString('errorcontactingserver', []);
  720.         performancingUI.addItemToRSSList(localeString, '');
  721.     }
  722. }
  723.  
  724. performancingUI.addItemToRSSList = function(aTitle, aURL) {
  725. /*
  726.   <label value="Some title here" class="url performancerssitem" onclick="performancingUI.openInTab('http://someurl.com');" crop="right" />
  727. */
  728.     var theVbox = document.getElementById('performancing-about-rss');
  729.     var theLabel = document.createElement('label');
  730.     theLabel.setAttribute('value', aTitle);
  731.     theLabel.setAttribute('class', 'url performancerssitem');
  732.     theLabel.setAttribute('crop', 'right');
  733.     theLabel.setAttribute('width', '200px');
  734.     theLabel.setAttribute('onclick', "performancingUI.openInTab('" + aURL + "');");
  735.     theVbox.appendChild(theLabel);
  736. }
  737.  
  738. performancingUI.uiINIT = function() {
  739.     //pffAddonSkin.loadLastSkin();//Load the users last UI CSS
  740.     
  741.     document.getElementById("performancing-editor-extra-pub").hidden =    !gPerformancingUtil.prefs.getBoolPref('settings.showextrapuboptions');
  742.     document.getElementById("performancing-technorati-tab").hidden =  gPerformancingUtil.prefs.getBoolPref('display.hidetechnorati');
  743.     document.getElementById("performancing-delicious-tab").hidden =     gPerformancingUtil.prefs.getBoolPref('display.hidedelicious');
  744.     document.getElementById("performancing-draft-checkbox").checked =  gPerformancingUtil.prefs.getBoolPref('publish.checkdraft');
  745.     //alert("Dude: "+document.getElementById("performancing-editor-extra-pub").hidden);
  746. }
  747.  
  748. performancingUI.toggleExtraOptDeck = function(forceClose) {
  749.     var extraOptsButton = document.getElementById("performancing-editor-extra-pub");
  750.     var extraOptDeck    = document.getElementById("performancing-editor-extra-pub-deck");
  751.     var sidebarContent    = document.getElementById("performancing-sidebar");
  752.     var extraoptContent = document.getElementById("performancing-sidebar-extra-options");
  753.     
  754.     if( extraOptDeck.getAttribute('selectedIndex') == 0 && !forceClose ){ //extraOptDeck.setAttribute('selectedIndex','0');
  755.         var newLabel = performancingUI.getLocaleString("closeoptions", []);
  756.         extraOptsButton.setAttribute('label', newLabel);
  757.         extraOptDeck.setAttribute('selectedIndex','1');
  758.         sidebarContent.setAttribute('collapsed', true);
  759.         extraoptContent.setAttribute('collapsed', false);
  760.     }else{
  761.         var newLabel = performancingUI.getLocaleString("publishingoptions", []);
  762.         extraOptsButton.setAttribute('label', newLabel);
  763.         extraOptDeck.setAttribute('selectedIndex','0');
  764.         sidebarContent.setAttribute('collapsed', false);
  765.         extraoptContent.setAttribute('collapsed', true);
  766.     }
  767. }
  768.  
  769. performancingUI.clearTechnoratiTags = function() {
  770.     gPFFLastTags = document.getElementById("performancing-technorati-tags").value;
  771.     document.getElementById("performancing-technorati-tags").value = "";
  772. }
  773.  
  774. performancingUI.insertTechnorati = function() {
  775.     var regXP = /class\=\"performancingtags/;
  776.     if( !performancingUI.checkIfContentMatch(regXP) ){
  777.         var theTagList = document.getElementById("performancing-technorati-tags").value;
  778.         if(theTagList != "" && theTagList != " " ){
  779.             //First clear out spaces following ','.
  780.             var re = /\,\s+/g;
  781.             theTagList = theTagList.replace(re, ",");
  782.             
  783.             var theTagArrayList = theTagList.split(",");
  784.             var theTagLinkArray = [];
  785.             for(i=0; i < theTagArrayList.length; i++ ){
  786.                 theTagLinkArray.push( this.createTechnoratiLinksArray( theTagArrayList[i] ) );
  787.             }
  788.             performancingUI.doechnoratiLinksInsert( theTagLinkArray );
  789.         }
  790.     }
  791.     
  792. }
  793.  
  794. performancingUI.createTechnoratiLinksArray = function(aTagName){
  795.     var aTagLink = "<a class=\"performancingtags\" href=\"http://technorati.com/tag/_tagname_\" rel=\"tag\">_tagname_</a>";
  796.     //turn double spaces to single space
  797.     var re = /\s\s+/g;
  798.     aTagName = aTagName.replace(re, " ");
  799.     
  800.     var re = /_tagname_/g;
  801.     aTagLink = aTagLink.replace(re, aTagName);
  802.     //alert("theTagLink: " + theTagLink);
  803.     return aTagLink;
  804. }
  805.  
  806. performancingUI.doechnoratiLinksInsert = function(theTagLinkArray) {
  807.     //var myIframeWindow = document.getElementById('perFormancingMidasFrame').contentDocument;
  808.     
  809.     //var textToAppend = "Technorati Tags:";
  810.     var textToAppend = performancingUI.getLocaleString('technoratitags', []);
  811.     
  812.     for(i=0; i < theTagLinkArray.length; i++ ){
  813.         if(i == theTagLinkArray.length-1){
  814.             textToAppend = textToAppend + " " + theTagLinkArray[i] + "";
  815.         }else{
  816.             textToAppend = textToAppend + " " +     theTagLinkArray[i] + ",";
  817.         }
  818.     }
  819.     
  820.     if(theTagLinkArray.length > 0){
  821.         performancingUI.appendText( textToAppend );
  822.     }
  823. }
  824.  
  825. performancingUI.insertPoweredByPFF = function() {
  826.     var regXP = /class\=\"poweredbyperformancing/;
  827.     if( !performancingUI.checkIfContentMatch(regXP) ){
  828.         var theText = '<p class="poweredbyperformancing">Powered by <a href="http://scribefire.com/">ScribeFire</a>.</p>';
  829.         performancingUI.appendText( theText );
  830.     }
  831. }
  832.  
  833. performancingUI.checkIfContentMatch = function(theRegExp) {
  834.     var tabbox = document.getElementById("performancing-editor-tabbox");
  835.     var theContent = "";
  836.     //var theTitle = myIframeWindow.getElementById("performancing-editor-subject").value;
  837.     if(tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){//Rich or preview
  838.         var winNormal = document.getElementById("performancing-message");
  839.         theContent = winNormal.contentWindow.document.body.innerHTML;
  840.     }else if(tabbox.selectedIndex == 1){ //Source
  841.         var theSourceBox = document.getElementById("performancing-message-source");
  842.         theContent = theSourceBox.value;
  843.     }else{
  844.         //alert('PerFormancing Error: Could not find Note content, please contact the author');
  845.         theContent = null;
  846.     }
  847.     if(theContent != null){
  848.         if(theRegExp.test(theContent)){
  849.             return true;
  850.         }
  851.     }
  852.     return false;
  853. }
  854.  
  855. performancingUI.appendText = function(theText) {
  856.     var tabbox = document.getElementById("performancing-editor-tabbox");
  857.     //var theTitle = myIframeWindow.getElementById("performancing-editor-subject").value;
  858.     if(tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){//Rich or preview
  859.         var winNormal = document.getElementById("performancing-message");
  860.         winNormal.contentWindow.document.body.innerHTML = winNormal.contentWindow.document.body.innerHTML + "<br/><br/>" + theText;
  861.     }else if(tabbox.selectedIndex == 1){ //Source
  862.         var theSourceBox = document.getElementById("performancing-message-source");
  863.         theSourceBox.value = theSourceBox.value + "\n\n" + theText;
  864.     }else{
  865.         //alert('PerFormancing Error: Could not find Note content, please contact the author');
  866.     }
  867. }
  868.  
  869. //insertPoweredByPFF
  870.  
  871. performancingUI.cssPreviewSaveNLoad = function() {
  872.     previewCSS = document.getElementById("performancing-settings-cssurl");
  873.     gPerformancingUtil.prefs.setCharPref("content.preview.cssurl", previewCSS.value);
  874.     
  875.     //Now Load it
  876.     performancingUI.setCSS();
  877. }
  878.  
  879. performancingUI.getLastPageURInTitle = function(){
  880.     var theWindow = performancingUI.getLastWindow();
  881.     var docWrapper = new XPCNativeWrapper(theWindow.content);
  882.     var theURL = docWrapper.location.href;
  883.     var theTitle = docWrapper.document.title
  884.     return [theURL, theTitle];
  885. }
  886.  
  887. performancingUI.getPageInfo = function(anAction){
  888.     var myLastWin = performancingUI.getLastWindow();
  889.     var thePageProps = this.getLastPageURInTitle();
  890.     var theURL = thePageProps[0];
  891.     var theTitle = thePageProps[1];
  892.     //var theURL = Components.lookupMethod(myLastWin._content, 'location').call(myLastWin._content).href;
  893.     //var theTitle = Components.lookupMethod(myLastWin._content.document, 'title').call(myLastWin._content.document);
  894.     var performancingSplinter = myLastWin.document.getElementById("performancingSplit");
  895.     if( theURL != gPerformanceLastURL ){
  896.         if(anAction == 'technorati'){
  897.             if( !performancingSplinter.collapsed ){
  898.                 document.getElementById("performancing-technorati-loading-img").hidden = false;
  899.                 //document.getElementById("performancing-technorati-title").value = "Loading...";
  900.                 var weAreLoading = performancingUI.getLocaleString('loading', []);
  901.                 document.getElementById("performancing-technorati-title").value = weAreLoading;
  902.                 //var RSSurl = 'http://technorat.com/node/feed/';
  903.                 var RSSurl = 'http://feeds.technorati.com/cosmos/rss/?partner=performancing&url=' + encodeURIComponent(theURL);
  904.                 
  905.                 //Set the Title
  906.                 document.getElementById("performancing-technorati-currentpagetitle").value = theTitle;
  907.                 gPerformanceLastURL = theURL;
  908.                 performancingUI.technoratiSetTimeOut();
  909.                 //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass)
  910.                 var theCall = new PffXmlHttpReq(RSSurl, "POST", '', false, null, null);
  911.                 
  912.                 theCall.onResult = function( aText, aXML ){
  913.                     performancingUI.setPageInfo( aText, theTitle );
  914.                 }
  915.                 theCall.onError = function (aStatusMsg, Msg) {
  916.                     //foo
  917.                 }
  918.                 theCall.prepCall(); //Set up The call (open connection, etc.)
  919.                 theCall.request.setRequestHeader("Content-Type", "text/xml");
  920.                 theCall.request.setRequestHeader("User-Agent", "ScribeFire " + gPerformancingVersionUA);
  921.                 theCall.makeCall(); //Make the call
  922.                 theCall.request.overrideMimeType ('text/xml');
  923.             }
  924.         }else if(anAction == 'delicious'){
  925.             performancingUI.deliciousClearBM();
  926.             document.getElementById("performancing-delicios-bookmark-url").value = theURL;
  927.             document.getElementById("performancing-delicios-bookmark-desc").value = theTitle;
  928.             performancingUI.deliciousGetPageInfo(theURL);
  929.         }
  930.     }
  931. }
  932.  
  933. performancingUI.setPageInfo = function(theData, thePageTitle) {
  934.     performancingUI.technoratiClearTimeOut();
  935.     var re = /(\<\?\xml[0-9A-Za-z\D]*\?\>)/;
  936.     var newstr = theData.replace(re, "");
  937.     var theXML = new XML(newstr);
  938.     //gPFFTempObject.push(theXML);
  939.     var t = new Namespace("tapi", "http://api.technorati.com/dtd/tapi-002.xml")
  940.     var theInboundBlogNum = theXML.channel.t::["result"].t::["inboundblogs"].toString();
  941.     var theInboundLinkNum = theXML.channel.t::["result"].t::["inboundlinks"].toString();
  942.     if(theInboundBlogNum == null || theInboundBlogNum == "" ){
  943.         theInboundBlogNum = "0";
  944.     }
  945.     if(theInboundLinkNum == null || theInboundLinkNum == "" ){
  946.         theInboundLinkNum = "0";
  947.     }
  948.     
  949.     var numberOfItems = theXML.channel.item.length();
  950.     gPerformancingUtil.clearCheckListOut("performancing-technorati-inboundlinks");
  951.     for(i = 0; i<numberOfItems && i < 10; i++ ){
  952.         performancingUI.addItemToTechnoratiList(theXML.channel.item[i].title, theXML.channel.item[i].link);
  953.     }
  954.     //performancingUI.addItemToTechnoratiList("More results...", theXML.channel.link + '/?partner=performancing');
  955.     document.getElementById("performancing-technorati-moreresults").setAttribute('onclick', "performancingUI.openInTab('" + theXML.channel.link + '/?partner=performancing' + "');")
  956.     
  957.     //Now set the info:
  958.     document.getElementById("performancing-technorati-linkcount").value = theInboundLinkNum;
  959.     document.getElementById("performancing-technorati-blogcount").value = theInboundBlogNum;
  960.     document.getElementById("performancing-technorati-loading-img").hidden = true;
  961.     document.getElementById("performancing-technorati-title").value = "Technorati";
  962. }
  963.  
  964. performancingUI.addItemToTechnoratiList = function(aTitle, aURL){
  965.     var theVbox = document.getElementById('performancing-technorati-inboundlinks');
  966.     var theLabel = document.createElement('label');
  967.     theLabel.setAttribute('value', " " +aTitle);
  968.     theLabel.setAttribute('class', 'url performancerssitem');
  969.     theLabel.setAttribute('maxwidth', '300px');
  970.     theLabel.setAttribute('crop', 'right');
  971.     theLabel.setAttribute('style', 'font-size: x-small');
  972.     theLabel.setAttribute('tooltiptext', aURL);
  973.     theLabel.setAttribute('onclick', "performancingUI.openInTab('" + aURL + "');");
  974.     theVbox.appendChild(theLabel);
  975. }
  976.  
  977. performancingUI.onTechnoratiKeyPress = function(anEvent){
  978.     if(anEvent.keyCode == 13){
  979.             performancingUI.onTechnoratiSearch();
  980.     }
  981. }
  982.  
  983. performancingUI.onTechnoratiSearch = function(){
  984.     var itemURL = 'http://technorati.com/search/' + document.getElementById('performancing-technorati-srchtechnorati').value + '?partner=performancing';
  985.     performancingUI.openInTab(itemURL);
  986. }
  987.  
  988. performancingUI.technoratiSetTimeOut = function(){
  989.     gPffTechnoratiTimeOut = window.setTimeout('performancingUI.technoratiOnTimeOut()', 20000);
  990. }
  991.  
  992. performancingUI.technoratiOnTimeOut = function(){
  993.     var errorMessage = performancingUI.getLocaleString('technoratitimeout', []);
  994.     //Sorry, Technorati has timed out. Their service might be down or unstable, please try again.
  995.     alert(errorMessage);
  996. }
  997.  
  998. performancingUI.technoratiClearTimeOut = function(){
  999.     window.clearTimeout(gPffTechnoratiTimeOut);
  1000. }
  1001. //
  1002. performancingUI.deliciousSetTimeOut = function(){
  1003.     gPffDeliciousTimeOut = window.setTimeout('performancingUI.deliciousOnTimeOut()', 20000);
  1004. }
  1005.  
  1006. performancingUI.deliciousOnTimeOut = function(){
  1007.     //alert("Sorry, Delicious has timed out. Their service might be down or unstable, please try again.");
  1008.     //Login
  1009.     document.getElementById('performancing-delicios-loading-img').hidden = true;
  1010.     //Save Bookmark
  1011.     document.getElementById('performancing-delicios-saving-img').hidden = true;
  1012. }
  1013.  
  1014. performancingUI.deliciousClearTimeOut = function(){
  1015.     window.clearTimeout(gPffDeliciousTimeOut);
  1016. }
  1017.  
  1018. performancingUI.deliciousOnLoad = function(){
  1019.     var savePassword = gPerformancingUtil.prefs.getBoolPref("extra.delicious.savePassword");
  1020.     if(savePassword){
  1021.         var theUserName = gPerformancingUtil.prefs.getCharPref("extra.delicious.login");
  1022.         if(theUserName != "" && theUserName != "null" ){
  1023.             document.getElementById('performancing-delicios-login-username').value = theUserName;
  1024.             document.getElementById('performancing-delicios-login-password').value = gPerformancingUtil.goGetPassword(theUserName, "pff-delicious");
  1025.             performancingUI.deliciousLogin();
  1026.         }
  1027.     }
  1028.     document.getElementById('performancing-delicios-login-save').checked = savePassword;
  1029. }
  1030.  
  1031. performancingUI.deliciousOnSaveCheck = function(){
  1032.     var savePassword = document.getElementById('performancing-delicios-login-save').checked;
  1033.     gPerformancingUtil.prefs.setBoolPref("extra.delicious.savePassword", !savePassword);
  1034.     
  1035. }
  1036.  
  1037. performancingUI.doDeliciousCall = function(theURL, message, theAction, userName, passWord, doAuth){
  1038.     //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass)
  1039.     var theCall = new PffXmlHttpReq(theURL, "GET", message, doAuth, userName, passWord);
  1040.     
  1041.     theCall.onResult = function( aText, aXML ){
  1042.         performancingUI.deliciousResponse( aText, message, theAction, userName, passWord);
  1043.     }
  1044.     theCall.onError = function (aStatusMsg, Msg) {
  1045.         //foo
  1046.     }
  1047.     theCall.prepCall(); //Set up The call (open connection, etc.)
  1048.     theCall.request.setRequestHeader("Content-Type", "text/xml");
  1049.     theCall.request.setRequestHeader("User-Agent", "ScribeFire " + gPerformancingVersionUA);
  1050.     theCall.makeCall(); //Make the call
  1051.     theCall.request.overrideMimeType ('text/xml');
  1052. }
  1053.  
  1054. performancingUI.deliciousLogin = function(){
  1055.     document.getElementById('performancing-delicios-loading-img').hidden = false;
  1056.     performancingUI.deliciousSetTimeOut();
  1057.     if( performancingUI.deliciousIsLoggedIn() ){
  1058.         //performancingUI.getPageInfo('delicious');
  1059.     }else{
  1060.         var theUserName = gPerformancingUtil.prefs.getCharPref("extra.delicious.login");
  1061.         var userName = document.getElementById('performancing-delicios-login-username').value;
  1062.         var passWord = document.getElementById('performancing-delicios-login-password').value;
  1063.         
  1064.         if(theUserName != 'null' && (userName == "" || passWord == "" )){
  1065.             var errorMessage = performancingUI.getLocaleString('delicioususererror', []);
  1066.             //Please make sure you have entered a Username and Password
  1067.             alert(errorMessage);
  1068.         }else{
  1069.             performancingUI.doDeliciousCall('https://api.del.icio.us/v1/posts/update', '', 'login', userName, passWord, true);
  1070.         }
  1071.     }
  1072. }
  1073.  
  1074. performancingUI.deliciousResponse = function(aResponse, aMessage, anAction, userName, passWord){
  1075.     //alert('Response Baby: ' +aResponse);
  1076.     //If save password
  1077.     //var savePassword = gPerformancingUtil.prefs.getBoolPref("extra.delicious.savePassword");
  1078.     var re = /(\<\?\xml[0-9A-Za-z\D]*\?\>)/;
  1079.     var newResponse = aResponse.replace(re, "");
  1080.         
  1081.     switch(anAction){
  1082.         case 'login':
  1083.             performancingUI.deliciousClearTimeOut();
  1084.             if(newResponse.search("update time") != -1 ){//If we really logged in
  1085.                 var savePassword = document.getElementById('performancing-delicios-login-save').checked;
  1086.                 if(savePassword){
  1087.                     var addedUser = gPerformancingUtil.usermanagment.storeLoginDetails(userName, passWord, "pff-delicious");
  1088.                     gPerformancingUtil.prefs.setCharPref("extra.delicious.login", userName);
  1089.                 }
  1090.                 document.getElementById('performancing-delicios-deck').setAttribute('selectedIndex', '1');
  1091.                 performancingUI.getPageInfo('delicious');
  1092.                 performancingUI.getTags('delicious');
  1093.             }else{
  1094.                 var errorMessage = performancingUI.getLocaleString('deliciousloginerror', []);
  1095.                 //Error logging into Del.Icio.Us, please check your username and password, and try again.
  1096.                 alert(errorMessage + "\n" + newResponse);
  1097.             }
  1098.             document.getElementById('performancing-delicios-loading-img').hidden = true;
  1099.             break;
  1100.             
  1101.         case 'pageInfo':
  1102.             var myXML = new XML(newResponse);
  1103.             if(myXML.post.length() >= 1){
  1104.                 document.getElementById('performancing-delicios-bookmark-url').value = myXML.post.@href;
  1105.                 document.getElementById('performancing-delicios-bookmark-desc').value = myXML.post.@description;
  1106.                 var theTags = myXML.post.@tag;
  1107.                 if(theTags == "system:unfiled"){
  1108.                     theTags="";
  1109.                 }
  1110.                 document.getElementById('performancing-delicios-bookmark-tags').value = theTags;
  1111.                 document.getElementById('performancing-delicios-bookmark-notes').value = myXML.post.@extended;
  1112.             }
  1113.             break;
  1114.             
  1115.         case 'createbm':
  1116.             //alert('Created Bookmark');
  1117.             performancingUI.deliciousClearTimeOut();
  1118.             document.getElementById('performancing-delicios-saving-img').hidden = true;
  1119.             performancingUI.deliciousClearBM();
  1120.             performancingUI.getTags('delicious');
  1121.             break;
  1122.             
  1123.         case 'getTags':
  1124.             var myXML = new XML(newResponse);
  1125.             gPffDeliciosTagArray = [];
  1126.             if(myXML.tag.length() >= 1){
  1127.                 for(i=0; i < myXML.tag.length(); i++){
  1128.                     gPffDeliciosTagArray.push( myXML.tag[i].@tag );
  1129.                 }
  1130.             }
  1131.             performancingUI.deliciousLoadTags();
  1132.             break;
  1133.             
  1134.     }
  1135.     //
  1136.     
  1137. }
  1138.  
  1139. performancingUI.deliciousGetPageInfo = function(aURL){
  1140.     if( performancingUI.deliciousIsLoggedIn() ){
  1141.         performancingUI.doDeliciousCall('https://api.del.icio.us/v1/posts/get?url='+aURL, '', 'pageInfo', '', '', false);
  1142.     }
  1143. }
  1144.  
  1145. performancingUI.deliciousIsLoggedIn = function(){
  1146.     if ( document.getElementById('performancing-delicios-deck').getAttribute('selectedIndex') == '1' ){
  1147.         return true;
  1148.     }
  1149.     return false;
  1150. }
  1151.  
  1152. performancingUI.deliciousPostBookmark = function(){
  1153.      if( performancingUI.deliciousIsLoggedIn() ){
  1154.         performancingUI.deliciousSetTimeOut();
  1155.         document.getElementById('performancing-delicios-saving-img').hidden = false;
  1156.         var theUrl = document.getElementById('performancing-delicios-bookmark-url').value;
  1157.         var theDesc = document.getElementById('performancing-delicios-bookmark-desc').value;
  1158.         var theNotes = document.getElementById('performancing-delicios-bookmark-notes').value;
  1159.         var theTags = document.getElementById('performancing-delicios-bookmark-tags').value;
  1160.         performancingUI.doDeliciousCall('https://api.del.icio.us/v1/posts/add?url='+theUrl+'&description='+theDesc+'&extended='+theNotes+'&tags='+theTags, '', 'createbm', '', '', false);
  1161.     }
  1162. }
  1163.  
  1164. performancingUI.deliciousClearBM = function(){
  1165.     document.getElementById('performancing-delicios-bookmark-url').value = "";
  1166.     document.getElementById('performancing-delicios-bookmark-desc').value = "";
  1167.     document.getElementById('performancing-delicios-bookmark-tags').value = "";
  1168.     document.getElementById('performancing-delicios-bookmark-notes').value = "";
  1169. }
  1170.  
  1171. performancingUI.getTags = function(aService){
  1172.     //http://del.icio.us/api/tags/get
  1173.     if(aService == 'delicious'){
  1174.         window.setTimeout("performancingUI.doDeliciousCall('https://api.del.icio.us/v1/tags/get', '', 'getTags', '', '', false)", 1000, true);
  1175.     }
  1176. }
  1177.  
  1178. performancingUI.deliciousLoadTags = function(){
  1179.     gPerformancingUtil.clearCheckListOut("performancing-delicios-tag-list");
  1180.     var userName = gPerformancingUtil.prefs.getCharPref("extra.delicious.login");
  1181.     for(i=0; i < gPffDeliciosTagArray.length; i++){
  1182.         performancingUI.deliciousAddTags(userName, gPffDeliciosTagArray[i]);
  1183.     }
  1184. }
  1185.  
  1186. performancingUI.deliciousAddTags = function(aName, aTag){
  1187.         var tagList = document.getElementById('performancing-delicios-tag-list');
  1188.         var theLabel = document.createElement('label');
  1189.         theLabel.setAttribute('value', " " +gPffDeliciosTagArray[i]);
  1190.         theLabel.setAttribute('class', "url");
  1191.         theLabel.setAttribute('width', "200px");
  1192.         theLabel.setAttribute('crop', "end");
  1193.         theLabel.setAttribute('onclick', "performancingUI.openInTab('" + "http://del.icio.us/"+aName+"/"+aTag+ "');");
  1194.         tagList.appendChild(theLabel);
  1195. }
  1196.  
  1197. performancingUI.autocomplete = function(theInput,event){
  1198.     var tmp = "";
  1199.     try{
  1200.         tmp = theInput.value.toLowerCase();
  1201.     }catch(e){
  1202.         return 1;
  1203.     }
  1204.     if (tmp == ""){
  1205.         //alert("tmp=0");
  1206.         return 1;
  1207.     }
  1208.     for (var z=0;z<gPffDeliciosTagArray.length;z++){
  1209.         var tmp2 = gPffDeliciosTagArray[z].toLowerCase();
  1210.         var count = 0;
  1211.         for (var i = 0;i<tmp.length;i++){
  1212.             if (tmp2.charAt(i) == tmp.charAt(i)){
  1213.                 count++
  1214.             }
  1215.         }
  1216.         if (count == tmp.length){
  1217.             var diff = tmp2.length - tmp.length;
  1218.             if (diff <= 0) break;
  1219.             var kap = "";
  1220.             for (i=0;i<tmp2.length;i++){
  1221.                 if (i >= tmp.length) kap += tmp2.charAt(i);
  1222.             }
  1223.             theInput.backspace = true;
  1224.             tmp = kap;
  1225.             
  1226.             //Insert Guessed Word
  1227.             var temp_n = theInput.value.length;
  1228.             theInput.value = gPffDeliciosTagArray[z];
  1229.             
  1230.             //Get Selection
  1231.             theInput.selectionEnd = theInput.value.length + temp_n;
  1232.             theInput.selectionStart = temp_n;
  1233.             return 0;
  1234.         }else{
  1235.             return 1;
  1236.         }
  1237.     }
  1238.     return 1;
  1239. }
  1240.  
  1241. //onkeyup="fareCompareA.getKeys(this,event)"
  1242. performancingUI.getKeys = function(theInput,event){
  1243.     if (theInput.value == "") {
  1244.         performancingUI.deliciousLoadTags();
  1245.     }
  1246.     
  1247.     if (event.keyCode == 8){
  1248.         //dontGetArray = "0";
  1249.         //return 0;
  1250.     }/*else if(event.keyCode == 8){
  1251.         theInput.selectionStart = theInput.selectionEnd;
  1252.     }*/
  1253.     
  1254.     if(performancingUI.autocomplete(theInput,event) == 1){
  1255.         performancingUI.deliciousAddSearch(theInput.value)
  1256.     }
  1257. }
  1258. //str.substr(0,10)
  1259. performancingUI.deliciousAddSearch = function(theInput){
  1260.     var myLength = theInput.length;
  1261.     gPerformancingUtil.clearCheckListOut("performancing-delicios-tag-list");
  1262.     var userName = gPerformancingUtil.prefs.getCharPref("extra.delicious.login");
  1263.     
  1264.     for(i=0; i < gPffDeliciosTagArray.length; i++){
  1265.         if( theInput == gPffDeliciosTagArray[i].substr(0,myLength) ){
  1266.             performancingUI.deliciousAddTags(userName, gPffDeliciosTagArray[i]);
  1267.         }
  1268.     }
  1269. }
  1270.  
  1271. performancingUI.deliciousAddTechnorati = function(aLink, aTitle, isAtom, atomEditURI){
  1272.     //alert("link: " + aLink + "\nTitle: " + aTitle + "\nisAtom: " + isAtom + "\natomEditURI: " + atomEditURI);
  1273.     var isChecked = document.getElementById('performancing-addto-delicious-checkbox').checked;
  1274.     if(isChecked){
  1275.         //Login
  1276.         if( !performancingUI.deliciousIsLoggedIn() ){
  1277.             performancingUI.deliciousOnLoad();
  1278.             var savePassword = gPerformancingUtil.prefs.getBoolPref("extra.delicious.savePassword");
  1279.             if(savePassword){
  1280.                 performancingUI.deliciousLogin();
  1281.             }
  1282.         }
  1283.         
  1284.         var theTagList = document.getElementById("performancing-technorati-tags").value;
  1285.         if(theTagList == "" || theTagList == " "){
  1286.            theTagList = gPFFLastTags;
  1287.         }
  1288.         
  1289.         var theTagArrayList = [];
  1290.         if(theTagList != "" && theTagList != " " ){
  1291.             //First clear out spaces following ','.
  1292.             var re = /\,\s+/g;
  1293.             theTagList = theTagList.replace(re, ",");
  1294.             theTagArrayList = theTagList.split(",");
  1295.         } 
  1296.         isAtom = false; //For blogger Beta fix
  1297.         if(isAtom){
  1298.             //gMakeXMLCall2(atomEditURI, '', 'atomAPIpost', theTagArrayList, '');
  1299.             var theCall = new PffXmlHttpReq(atomEditURI, "GET", null, false, null, null);
  1300.     
  1301.             theCall.onResult = function( aText, aXML ){
  1302.                 performancingUI.addDeliciousTechnoratiATOM( aText, theTagArrayList );
  1303.             }
  1304.             theCall.onError = function (aStatusMsg, Msg) {
  1305.                 //foo
  1306.             }
  1307.             theCall.prepCall(); //Set up The call (open connection, etc.)
  1308.             theCall.request.setRequestHeader("Content-Type", "text/xml");
  1309.             theCall.request.setRequestHeader("User-Agent", "ScribeFire " + gPerformancingVersionUA);
  1310.             theCall.makeCall(); //Make the call
  1311.             theCall.request.overrideMimeType ('text/xml');
  1312.         }else{
  1313.             performancingUI.addDeliciousTechnoratiBM( aLink, aTitle, theTagArrayList );
  1314.         }
  1315.     }
  1316. }
  1317.  
  1318. performancingUI.addDeliciousTechnoratiBM = function(theURL, theDesc, theTags){
  1319.     var tagSpaceList = "";
  1320.     for(i=0; i < theTags.length; i++){
  1321.         tagSpaceList = tagSpaceList + " " + theTags[i];
  1322.     }
  1323.     var theCallURL = 'https://api.del.icio.us/v1/posts/add?tags='+tagSpaceList+'&url='+ encodeURIComponent(theURL) +'&description='+ encodeURIComponent(theDesc) ;
  1324.     //alert("theCallURL: " + theCallURL + " theTags: " + theTags + " gPFFLastTags: " + gPFFLastTags);
  1325.     performancingUI.doDeliciousCall(theCallURL, '', 'createbm', '', '', false);
  1326. }
  1327.  
  1328. performancingUI.addDeliciousTechnoratiATOM = function(aResponse, theTags){
  1329.     //Parse the post
  1330.     var re = /(\<\?\xml[0-9A-Za-z\D]*\?\>)/;
  1331.     var newstr = aResponse.replace(re, "");
  1332.     
  1333.     var t = new Namespace("tapi", "http://purl.org/atom/ns#")
  1334.     var myXML = new XML(newstr);
  1335.     var aLink  = myXML.t::link[1].@href;
  1336.     var aTitle = myXML.t::title;
  1337.     
  1338.     performancingUI.addDeliciousTechnoratiBM( aLink, aTitle, theTags );
  1339. }
  1340.  
  1341. performancingUI.sendTrackBacks = function(aTitle, aLink, aBlogName){
  1342.     var theTrackBackList = document.getElementById("performancing-trackback-textbox").value;
  1343.     //alert("theTrackBackList: " + theTrackBackList + " gPFFLastTrackbacks: " +gPFFLastTrackbacks);
  1344.     if(theTrackBackList != ""){
  1345.         gPFFLastTrackbacks = theTrackBackList;
  1346.     }else{
  1347.         theTrackBackList = gPFFLastTrackbacks;
  1348.     }
  1349.     if(theTrackBackList != "" && theTrackBackList != null ){
  1350.         var theTrackBackArray = [];
  1351.         if(theTrackBackList != "" && theTrackBackList.length > 4){
  1352.             theTrackBackArray = theTrackBackList.split(",");
  1353.         }
  1354.         for(i=0; i < theTrackBackArray.length; i++){
  1355.             performancingUI.trackbackCall(theTrackBackArray[i], aLink, aTitle,    aBlogName, i, false );
  1356.         }
  1357.     }
  1358.     //theTrackBackList.value = "";
  1359. }
  1360.  
  1361. performancingUI.trackbackCall = function( theURL, aLink, aTitle, aBlogName, aNumber, aSecondTry ){
  1362.     var theCompleteURL = theURL + "&title="+aTitle+"&url="+aLink+ "&blog_name=" +aBlogName;
  1363.     //gMakeTrackBackXMLCall(theURL, theCompleteURL, 'trackback', '', aNumber, aSecondTry, '');
  1364.     //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass)
  1365.     var theCall = new PffXmlHttpReq(theURL, "POST", theCompleteURL, false, null, null);
  1366.     
  1367.     theCall.onResult = function( aText, aXML ){
  1368.         performancingUI.trackBackResponse( aText, theURL, theCompleteURL, 'trackback', '', aNumber, aSecondTry, '');
  1369.     }
  1370.     theCall.onError = function (aStatusMsg, Msg) {
  1371.         //foo
  1372.     }
  1373.     theCall.prepCall(); //Set up The call (open connection, etc.)
  1374.     theCall.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  1375.     theCall.makeCall(); //Make the call
  1376.     theCall.request.overrideMimeType ('text/xml');
  1377.     
  1378. }
  1379.  
  1380. performancingUI.trackBackResponse = function( aData, theURL, message, theAction, additionalInfo, aNumber, aSecondTry, theGUID){
  1381.     //alert('ANumber: '+aNumber+' aSecondTry: '+aSecondTry+' and TrackBack Success: ' + aData);
  1382.     var isSuccess = "<error>0</error>";
  1383.     var isError = "<error>1</error>";
  1384.     
  1385.     var isRDF = /(?:trackback:ping=\")(.*)(?:\")/mgi;
  1386.     //var isRDF = /(?:\trackback\:\ping\=\")((http|https):\/\/[a-zA-Z0-9@:%_~#?&=.,\/;-]*[a-zA-Z0-9@:%_~#&=\/;-])(?:\".+)(?=\")/mgi;
  1387.     var isLink = /(?:\<\a\ \href\=\")((http|https):\/\/[a-zA-Z0-9@:%_~#?&=.,\/;-]*[a-zA-Z0-9@:%_~#&=\/;-])(?=\"\srel="trackback">)|(?:\<\a\ \href\=\")((http|https):\/\/[a-zA-Z0-9@:%_~#?&=.,\/;-]*[a-zA-Z0-9@:%_~#&=\/;-])(?=\"\>trackback\<)/mgi;
  1388.     //var isLink2 = /(?:\<\a\ \href\=\")((http|https):\/\/[a-zA-Z0-9@:%_~#?&=.,\/;-]*[a-zA-Z0-9@:%_~#&=\/;-])(?=\"\>trackback\<)/mgi;
  1389.     //gPffTrackBackTemp = aData;
  1390.     if( aData.search(isSuccess) != -1){ //If succesfull
  1391.         //alert('It was GOOD! aSecondTry" ' + aSecondTry);
  1392.     }else if(aData.search(isError) != -1 ){ //If error but url was right
  1393.         //alert('It was a good trackback call but got rejected! aSecondTry" ' + aSecondTry);
  1394.     }else{ // url must be wrong, let's look for a real trackback url
  1395.         if(!aSecondTry){ //Make sure it's not already the second try
  1396.             //(?:trackback:ping=\")(.*)(?:\")
  1397.             //(?:\<\a\ \href\=\")((http|https):\/\/[a-zA-Z0-9@:%_~#?&=.,\/;-]*[a-zA-Z0-9@:%_~#&=\/;-])(?:\".+)(?=rel="trackback">)
  1398.             var isAnRDF =  aData.match(isRDF);
  1399.             var isALink =  aData.match(isLink);
  1400.             //alert("isAnRDF: " + isAnRDF +"\n isALink: "+isALink );
  1401.             if(isAnRDF != null){
  1402.                 isAnRDF = isAnRDF.toString().replace(/trackback:ping=\"/, ""); //We need better regexps
  1403.                 isAnRDF = isAnRDF.replace(/"/, "");
  1404.                 //gMakeTrackBackXMLCall(isAnRDF, message, 'trackback', '', aNumber, true, '');
  1405.                 //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass)
  1406.                 var theCall = new PffXmlHttpReq(isAnRDF, "POST", message, false, null, null);
  1407.                 
  1408.                 theCall.onResult = function( aText, aXML ){
  1409.                     performancingUI.trackBackResponse( aText, isAnRDF, message, 'trackback', '', aNumber, true, '');
  1410.                 }
  1411.                 theCall.onError = function (aStatusMsg, Msg) {
  1412.                     //foo
  1413.                 }
  1414.                 theCall.prepCall(); //Set up The call (open connection, etc.)
  1415.                 theCall.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  1416.                 theCall.makeCall(); //Make the call
  1417.                 theCall.request.overrideMimeType ('text/xml');
  1418.             }else if(isALink != null){
  1419.                 isALink = isALink.toString().replace(/<a href="/, ""); //We need better regexps 
  1420.                 isALink = isALink.replace(/"/, "");
  1421.                 //gMakeTrackBackXMLCall(isALink, message, 'trackback', '', aNumber, true, '');
  1422.                 //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass)
  1423.                 var theCall = new PffXmlHttpReq(isALink, "POST", message, false, null, null);
  1424.                 
  1425.                 theCall.onResult = function( aText, aXML ){
  1426.                     performancingUI.trackBackResponse( aText, isALink, message, 'trackback', '', aNumber, true, '');
  1427.                 }
  1428.                 theCall.onError = function (aStatusMsg, Msg) {
  1429.                     //foo
  1430.                 }
  1431.                 theCall.prepCall(); //Set up The call (open connection, etc.)
  1432.                 theCall.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  1433.                 theCall.makeCall(); //Make the call
  1434.                 theCall.request.overrideMimeType ('text/xml');
  1435.             }else{
  1436.                 //alert('Fail, seems there is not a trackback link aSecondTry" ' + aSecondTry);
  1437.             }
  1438.         }
  1439.     }
  1440. }
  1441.  
  1442. performancingUI.clearTrackbacks = function(isClear) {
  1443.     document.getElementById("performancing-trackback-textbox").value ="";
  1444. }
  1445.  
  1446. //For bebugging, you must have FireBug installed.
  1447. //performancingUI.printfire(whatever);
  1448. performancingUI.printfire = function(){
  1449.     if (document.createEvent)
  1450.     {
  1451.         printfire.args = arguments;
  1452.         var ev = document.createEvent("Events");
  1453.         ev.initEvent("printfire", false, true);
  1454.         dispatchEvent(ev);
  1455.     }
  1456. }
  1457. //performancingUI.doPing( theMethodName, theBlogName, theBlogURL );
  1458. performancingUI.doPing = function( theBlogName, theBlogURL ){
  1459.     //alert("Ping Baby");
  1460.     if( document.getElementById("performancing-enablepings-checkbox").checked ) {
  1461.         var tempArray = [];
  1462.         var selectedPing =    document.getElementById("performancing-pingradio-group").selectedItem.value;
  1463.         if(selectedPing == 'custom'){
  1464.             var checkList = document.getElementById("performancing-pinglist-vbox");
  1465.             for(i=0; i < checkList.childNodes.length; i++ ){
  1466.                 try{
  1467.                     if(checkList.childNodes[i].checked){
  1468.                         var tempString = checkList.childNodes[i].getAttribute("url");
  1469.                         tempArray.push(tempString);
  1470.                     }
  1471.                 }catch(e){
  1472.                     //foo
  1473.                 }
  1474.             }
  1475.             if(tempArray.length > 0){
  1476.                 for(x=0; x < tempArray.length; x++){
  1477.                     performancingUI.doRPCPing(theBlogName, theBlogURL, tempArray[x]);
  1478.                 }
  1479.             }
  1480.            // alert("tempArray: " + tempArray);
  1481.         }else{
  1482.             switch(selectedPing){
  1483.                 case 'pingomatic':
  1484.                     
  1485.                     var theRestURL = "http://pingomatic.com/ping/?title="+theBlogName+"&blogurl="+theBlogURL+"&rssurl=http%3A%2F%2F&chk_weblogscom=on&chk_blogs=on&chk_technorati=on&chk_feedburner=on&chk_syndic8=on&chk_newsgator=on&chk_feedster=on&chk_myyahoo=on&chk_pubsubcom=on&chk_blogdigger=on&chk_blogrolling=on&chk_blogstreet=on&chk_weblogalot=on&chk_icerocket=on";
  1486.                     performancingUI.doRestPing(theBlogName, theBlogURL, theRestURL);
  1487.                     break;
  1488.                     
  1489.                 case 'pingoat':
  1490.                     var theRestURL = "http://pingoat.com/index.php?pingoat=go&blog_name="+theBlogName+"&blog_url="+theBlogURL+"&rss_url=http%3A%2F%2F&cat_0=0&id%5B%5D=0&id%5B%5D=1&id%5B%5D=2&id%5B%5D=3&id%5B%5D=4&id%5B%5D=5&id%5B%5D=6&id%5B%5D=7&id%5B%5D=10&id%5B%5D=11&id%5B%5D=12&id%5B%5D=14&id%5B%5D=16&id%5B%5D=20&cat_1=0&cat_2=0";
  1491.                     performancingUI.doRestPing(theBlogName, theBlogURL, theRestURL);
  1492.                     break;
  1493.                     
  1494.                 default:
  1495.                     var errorMessage = performancingUI.getLocaleString('nopingtypeselected', []);
  1496.                     //No Ping Type Selected
  1497.                     alert(errorMessage);
  1498.                     break;
  1499.             }
  1500.         }
  1501.     }
  1502. }
  1503.  
  1504. performancingUI.doRestPing = function( theBlogName, theBlogURL, theRestURL ){
  1505.     //Now make RPC Call
  1506.    //gMakeXMLCall2(theRestURL, "", "ping" );
  1507.     var theCall = new PffXmlHttpReq(theRestURL, "GET", null, false, null, null);
  1508.     
  1509.     theCall.onResult = function( aText, aXML ){
  1510.         performancingUI.processPingRecData( aText, "", "ping");
  1511.     }
  1512.     theCall.onError = function (aStatusMsg, Msg) {
  1513.         //foo
  1514.     }
  1515.     theCall.prepCall(); //Set up The call (open connection, etc.)
  1516.     theCall.request.setRequestHeader("Content-Type", "text/xml");
  1517.     theCall.request.setRequestHeader("User-Agent", "ScribeFire " + gPerformancingVersionUA);
  1518.     theCall.makeCall(); //Make the call
  1519.     theCall.request.overrideMimeType ('text/xml');
  1520. }
  1521.  
  1522. performancingUI.doRPCPing = function( theBlogName, theBlogURL, rpcURL ){
  1523.     var theMethodName = "weblogUpdates.extendedPing";
  1524.     var theXMLtoSend = bfXMLRPC.makePingXML(theMethodName, theBlogName, theBlogURL);
  1525.     
  1526.     //Now make RPC Call
  1527.     //gMakePingXMLCall( rpcURL, theXMLtoSend, "" );
  1528.     //PffXmlHttpReq( aUrl, aType, aContent, aDoAuthBool, aUser, aPass) 
  1529.     var theCall = new PffXmlHttpReq(rpcURL, "POST", theXMLtoSend, false, null, null);
  1530.     
  1531.     theCall.onResult = function( aText, aXML ){
  1532.         performancingUI.processPingRecData( aText, theXMLtoSend, "");
  1533.     }
  1534.     theCall.onError = function (aStatusMsg, Msg) {
  1535.         //foo
  1536.     }
  1537.     theCall.prepCall(); //Set up The call (open connection, etc.)
  1538.     theCall.request.setRequestHeader("Content-Type", "text/xml");
  1539.     theCall.request.setRequestHeader("User-Agent", "ScribeFire " + gPerformancingVersionUA);
  1540.     theCall.makeCall(); //Make the call
  1541.     theCall.request.overrideMimeType ('text/xml');
  1542. }
  1543.  
  1544.  
  1545. performancingUI.processPingRecData = function( aData ){
  1546.     //alert("Ping Back: " + aData);
  1547. }
  1548.  
  1549. performancingUI.openImageUpload = function(){
  1550.     //alert("Ping Back: " + aData);
  1551.     var re = [];
  1552.     var ourURL = "";
  1553.     var theURL = [ourURL];
  1554.     var localeString = performancingUI.getLocaleString('imageinsertwindowtitle', []);
  1555.     window.openDialog("chrome://performancing/content/imageUpload.xul", localeString,"chrome,modal,centerscreen",re,theURL);
  1556.     if(re[0]){
  1557.       //alert("the URL to insert: " +theURL[0]);
  1558.       return theURL[0];
  1559.     }
  1560.     return false;
  1561. }
  1562.  
  1563. /*
  1564.     For testing Image Uploads
  1565. */
  1566. performancingUI.openImageUpload2 = function(){
  1567.     //alert("Ping Back: " + aData);
  1568.     var re = [];
  1569.     var ourURL = "";
  1570.     var theURL = [ourURL];
  1571.     var localeString = performancingUI.getLocaleString('imageinsertwindowtitle', []);
  1572.     window.openDialog("chrome://performancing/content/imageUpload.xul", localeString,"chrome,modal,centerscreen",re,theURL);
  1573.     if(re[0]){
  1574.       //alert("the URL to insert: " +theURL[0]);
  1575.       return theURL[0];
  1576.     }
  1577.     return false;
  1578. }
  1579.  
  1580. performancingUI.openFileUpload = function(){
  1581.     //alert("Ping Back: " + aData);
  1582.     var re = [];
  1583.     var ourURL = "";
  1584.     var theURL = [ourURL];
  1585.     var localeString = performancingUI.getLocaleString('fileinsertwindowtitle', []);
  1586.     window.openDialog("chrome://performancing/content/fileUpload.xul", localeString,"chrome,modal,centerscreen",re,theURL);
  1587.     if(re[0]){
  1588.       //alert("the URL to insert: " +theURL[0]);
  1589.       return theURL[0];
  1590.     }
  1591.     return false;
  1592. }
  1593.  
  1594.  
  1595. performancingUI.onTextBoxLoad2 = function(){
  1596.     var prefsService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  1597.     var prefs = prefsService.getBranch("performancing.");
  1598.     var isRTL = prefs.getBoolPref('display.enablertl');
  1599.     var theStyle = "direction:rtl;";
  1600.     if(!isRTL){
  1601.         theStyle = "";
  1602.     }
  1603.         
  1604.         try{
  1605.             var winPreview = document.getElementById("performancing-preview-display");
  1606.             winPreview.contentDocument.getElementById("performancing-richtext").setAttribute('style', theStyle);
  1607.         }catch(e){
  1608.         }
  1609.         
  1610.         try{
  1611.             var winPreview = document.getElementById("performancing-message");
  1612.             winPreview.contentDocument.getElementById("performancing-richtext").setAttribute('style', theStyle);
  1613.         }catch(e){
  1614.         }
  1615.         
  1616.         try{
  1617.             document.getElementById("performancing-editor-subject").setAttribute('style', theStyle);
  1618.         }catch(e){
  1619.         }
  1620.         
  1621.         try{
  1622.             document.getElementById("performancing-message-source").setAttribute('style', theStyle);
  1623.         }catch(e){
  1624.         }
  1625. }
  1626.  
  1627. performancingUI.getLocaleString = function(strName, formattingValues){
  1628.         var str = null;
  1629.         try {
  1630.             var strbundle = document.getElementById("performancingstrings");
  1631.             var strbundleFallback = document.getElementById("performancingstrings-fallback");
  1632.             if (formattingValues === undefined) {
  1633.                 try {
  1634.                     str = strbundle.getString("performancing." + strName);
  1635.                 }catch(e) {
  1636.                     str = strbundleFallback.getString("performancing." + strName);
  1637.                 }
  1638.             } else {
  1639.                 try {
  1640.                     str = strbundle.getFormattedString("performancing." + strName, formattingValues);
  1641.                 }catch(e) {
  1642.                     str = strbundleFallback.getFormattedString("performancing." + strName, formattingValues);
  1643.                 }
  1644.             }
  1645.         } catch (err) {
  1646.             //this.printLine("Couldn't get string: " + strName + "\nErr: " + err );
  1647.         }
  1648.         return str;
  1649. }
  1650.  
  1651. performancingUI.hasCheckboxChildren = function(checkListIDname){
  1652.     var theCheckList = document.getElementById(checkListIDname);
  1653.     if( theCheckList.hasChildNodes() ){
  1654.         return (theCheckList.firstChild.nodeName == 'checkbox') ;
  1655.     }else{
  1656.         return false;
  1657.     }
  1658. }
  1659.  
  1660. performancingUI.hasLabelChild = function(checkListIDname){
  1661.     var theCheckList = document.getElementById(checkListIDname);
  1662.     if( theCheckList.hasChildNodes() ){
  1663.         return (theCheckList.firstChild.nodeName == 'label') ;
  1664.     }else{
  1665.         return false;
  1666.     }
  1667. }
  1668.  
  1669. performancingUI.addCategories = function(){
  1670.     var localeString = performancingUI.getLocaleString('addcategories', []);
  1671.     var theCategories = prompt(localeString);
  1672.     
  1673.     if ((theCategories != null) && (theCategories != "")){
  1674.         var theCategoryArray = theCategories.split(",");
  1675.         
  1676.         if (gPerformancingUtil.serviceObject.createCategories) {
  1677.             // The means that new categories can be created server-side
  1678.             // without adding them to a post right away.
  1679.             
  1680.             // Check to make sure that this category isn't in the list already.
  1681.             
  1682.             var checkList = document.getElementById("blog-sidebar-listing-categories");
  1683.             
  1684.             var theBlogXML = gPerformancingUtil.serviceObjectXML;
  1685.             var myServiceObject = gPerformancingUtil.serviceObject;
  1686.             
  1687.             newCategory : for (var i = 0; i < theCategoryArray.length; i++){
  1688.                 for (var j = 0; j < checkList.childNodes.length; j++) {
  1689.                     if (checkList.childNodes[j].getAttribute("label") == theCategoryArray[i]){
  1690.                         checkList.childNodes[j].setAttribute("checked", "true");
  1691.                         continue newCategory;
  1692.                     }
  1693.                 }
  1694.                 
  1695.                 var myResponse = myServiceObject.newCategory(theCategoryArray[i]);
  1696.                 
  1697.                 if(myResponse){
  1698.                     performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'newcategorycall', theCategoryArray[i], "", performancing_xmlcall.processData);
  1699.                 }
  1700.             }
  1701.         }
  1702.         
  1703.         performancingUI.addCategoriesToList(theCategoryArray);
  1704.     }
  1705. }
  1706.  
  1707. performancingUI.addCategoriesToList = function(theCategoryArray){
  1708.     var doNotCheckClear = performancingUI.hasCheckboxChildren('blog-sidebar-listing-categories');
  1709.     gPerformancingUtil.setCategoriesSidebar(theCategoryArray, !doNotCheckClear);
  1710. }
  1711.